<!-- 任务执行情况 -->
<template>
  <el-dialog title="围观类目" :visible.sync="dialogVisible" @close="closePOpup" :close-on-click-modal="false">
    <div class="cateBody">
      <el-form label-width="100px">
        <el-form-item label="类目名称">
          <el-input v-model="cateNameV" auto-complete="off" placeholder="填写围观类目"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closePOpup()" size="small">取 消</el-button>
      <el-button type="primary" @click="foodCheck()" size="small">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import api from '@/utils/api.js'
import {show_category_detail, show_category_add, show_category_edit} from "@/api/admin/school"

export default {
  name: 'taskListDialog',
  props: ['visible', 'cateId'],
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        if (this.cateId) {
          this.getDetail()
        }
      }
    }
  },
  data() {
    return {
      dialogVisible: this.visible,
      cateNameV: ''
    }
  },
  created() {
  },
  methods: {
    getDetail() {
      show_category_detail({id: this.cateId}).then(res => {
        this.cateNameV = res.vo.name
      })
    },
    foodCheck() {
      if (!this.cateNameV) {
        this.$message.error('请填写类目名称')
      } else {
        let data_ = {
          name: this.cateNameV
        }
        if (this.cateId) {
          data_.id = this.cateId
          show_category_edit(data_).then(res => {
            this.$message.success('编辑成功')
            this.$emit('initPage', this.cateNameV)
            this.closePOpup()
          })
        } else {
          show_category_add(data_).then(res => {
            this.$message.success('编辑成功')
            this.closePOpup()
            this.$emit('initPage', this.cateNameV)
          })
        }
      }
    },
    closePOpup() {
      this.$emit('update:visible', false)
    }
  }
}
</script>
<style>
.cateBody {
  padding: 40px 0;
}
</style>
